﻿




using System.Web.Mvc;
using Hotpot.Extensions;
using Hotpot.Modules.CMS.Services;
using Hotpot.Modules.CMS.ViewModels;
using Hotpot.ViewModels;

namespace Hotpot.Modules.CMS.Filters
{
    public class PageListActionFilter : IActionFilter
    {
        private readonly IPageService pageService;

        public PageListActionFilter(IPageService pageService)
        {
            this.pageService = pageService;
        }

        #region IActionFilter Members

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            HotpotViewModel model = filterContext.Controller.ViewData.Model as HotpotViewModel;

            if (model != null)
                model.AddModelItem(new PageListViewModel(pageService.GetPages()));
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
        }

        #endregion
    }
}
